package com.atguigu10._enum;

/**
 * ClassName: PersonTest
 * Description:
 *
 * @Author liu
 * @Create 2024/11/12 22:28
 * @Version 1.0
 */
public class SeasonTest1 {
    public static void main(String[] args) {
       //测试方法
        //1.tospring()
        System.out.println(Season1.SPRING);
        System.out.println(Season1.AUTUMN);

        //2.name()
        System.out.println(Season1.AUTUMN.name());

        //3.values()
        //返回枚举类型的对象数组。该方法可以很方便地遍历所有的枚举值，
        Season1[] value = Season1.values();
        for (int i = 0; i <value.length ; i++) {
            System.out.println(value[i]);
        }



        // valueOf(String objName):
        // 返回当前枚举类中名称为objName的枚举类对象。
        String objName = "WINTER";
        //objName = "WINTER1";
        Season1 season1 = Season1.valueOf(objName);
        System.out.println(season1);


        //5.ordinal(),返回当前枚举常量的次序号，默认从0开始
        System.out.println(Season1.SUMMER.ordinal());


        //通过枚举类的对象调用重写接口中的方法
        Season1.AUTUMN.show();



    }
}

//接口
interface Info{
    void show();
}

//jdk5.0中使用enum关键字定义枚举类
enum Season1 implements Info{
    //1.必须在枚举类的开头声明多个对象。对象之间使用,隔开
    //.values();
    SPRING("春天","春暖花开"),
    SUMMER("夏天","夏日炎炎"),
    AUTUMN("秋天","秋高气爽"),
    WINTER("冬天","白雪皑皑");

    //2.声明当前类的对象的实例变量,使用private final修饰
    private final String seasonNAME;//名称
    private final String seasonDesc;//描述

    //3. 私有化类的构造器
    Season1(String seasonNAME, String seasonDesc) {
        this.seasonNAME = seasonNAME;
        this.seasonDesc = seasonDesc;
    }

    //4. 提供实例变量的get方法


    public String getSeasonNAME() {
        return seasonNAME;
    }

    public String getSeasonDesc() {
        return seasonDesc;
    }

    @Override
    public String toString() {
        return "Season1{" +
                "seasonNAME='" + seasonNAME + '\'' +
                ", seasonDesc='" + seasonDesc + '\'' +
                '}';
    }

    @Override
    public void show() {
        System.out.println("lllll");
    }
}